import pymysql

from core.config import settings



# 连接mysql
def get_conn():
    try:
        conn = pymysql.connect(host=settings.MYSQL_HOST,
                               port=settings.MYSQL_PORT,
                               user=settings.MYSQL_USER,
                               password=settings.MYSQL_PASSWORD,
                               charset=settings.MYSQL_CHARSET)
        print("数据库连接成功")
        return conn
    except Exception as e:
        print(f"数据库链接失败:{str(e)}")


# 列出所有数据库
def list_databases():
    conn = get_conn()
    cursor = conn.cursor()
    cursor.execute("SHOW DATABASES")












if __name__ == '__main__':
    conn = get_conn()